// pages/minePage/stateDetail/stateDetail.js
import {
  lgRequest
} from "../../../utils/ajax";

Page({
  /**
   * 页面的初始数据
   */
  data: {
    EquipmentDetail:'1111',
    tagName: [],
    stationServiceInfo: [],

    delectImgTag: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/19/713a49f43240fae4d44090d92d7f9cf6.png",
    showAddLabels: false,
    school: true,
    schoolField: true,
    schoolTeacher: true,
    schoolRoom: true,
    selectIndex: 1,
    stateIcon: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/48d65128f11cf13b8af351d66d104c59.png",
    locationPointer: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/5d84351eea011e2bd15001bd38aa3347.png",
    stateTypeList: [{
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/0d84f12212b493bba7c4be6499187f78.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/654faaa2e0e3815fb97ce1f88b0ac03b.png",
        name: "勘察",
        color: "#F9BF2E",
      },
      {
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/e2a524d902e3ce5ccf1aa37b019b3520.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/4fbd75e48387a674e3876698375a90f6.png",
        name: "施工",
        color: "#1A9CD9",
      },
      {
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/0e5f9ed56572a88ad95b7cd5b301dadc.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/4602a49848320bdd49445360bdeff353.png",
        name: "交付",
        color: "#16B76F",
      },
      {
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/0593d62d516d452b004d4e6e6afee120.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/e992f2ff7c8dd4b4c809b6375c0fa14f.png",
        name: "故障",
        color: "#E81826",
      },
      {
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/f5d1281b6304a09122ff9919e95dce77.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/72a2f63dc66ccfb6fd5b61ea4650055c.png",
        name: "拆除",
        color: "#FD7E5D",
      },
      {
        icon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/15b2c822dce457bf1538d830f6172e62.png",
        icon_active: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/4f46c8acd453e1317e862603d8d236db.png",
        name: "停用",
        color: "#FD7E5D",
      }
    ],
    redBg:"https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/9b362108a7b3d67529486e7bb8967388.png",
    greenBg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png",
    whiteBg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/f37e1fe6501f44eb5fb877eff35068f2.png",
    circle: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/ac0b6544db4ed907bf5444fc888409aa.png",
    photerIcon: "https://www.mengbaoonline.com:8182/profile/upload/2022/11/24/ca4a458299232ae12fd7f07cae307ba5.png",
    delectImg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/22/3dde82a7d3849f35b05b725d65a8cbbf.png",
    selectIndexType: 0,
    switchList: [
      {
        name: "取电",
        name_active: "取电",
        isSelect: false,
        nameDetail: "取电",
      },
      {
        name: "安装",
        name_active: "安装",
        isSelect: false,
        nameDetail: "安装",
      },
      {
        name: "核电",
        name_active: "核电",
        isSelect: false,
        nameDetail: "核电",
      },
      {
        name: "立杆",
        name_active: "立杆",
        isSelect: false,
        nameDetail: "立杆",
      },
      {
        name: "联网",
        name_active: "联网",
        isSelect: false,
        nameDetail: "联网",
      },
    ],
    switchListOne: [
      {
        name: "政府施工",
        name_active: "政府施工",
        isSelect: false,
        nameDetail: "政府施工",
      },
      {
        name: "不可抗力",
        name_active: "不可抗力",
        isSelect: false,
        nameDetail: "不可抗力",
      },
      {
        name: "其他",
        name_active: "其他",
        isSelect: false,
        nameDetail: "其他",
      },
    ],
    imageList: [
      "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png",
      "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png",
      "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png",
      "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/06/25/1f7f77a9b26ba601732b436a140c1e69.png",
    ],
    btnLeftImg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/04/9ec11435acbc937f9b506c751fe53065.png",
    btnRightImg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/04/5e1eacd047b1ef4caed8bd490f9397e1.png",
    clictImg: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/04/73a50ba8185ee0d15c4571b6bf16fa59.png",
    delectImgPop: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/19/713a49f43240fae4d44090d92d7f9cf6.png",
    selectSwitchItem: null,
    equipmentList: [],
    reportPop: false,
    statusBarHeight: getApp().globalData.statusBarHeight,
    titleBarHeight: getApp().globalData.titleBarHeight,
    sysInfo: getApp().globalData.sysInfo,
    isIphoneX: getApp().globalData.isIphoneX,
    selectList: [{
        label: "巡查记录",
      },
      {
        label: "站点信息",
      },
      {
        label: "取电信息",
      },
      {
        label: "取网信息",
      },
      {
        label: "设备档案",
      },
    ],
    selectKey: {},
    zhanIdInfo: "",
    siteContactList: [], //站点联系人
    maintenanceRecordsInfo: [],
    picStateInfoList: [], //站点图片
    fileList: [], //上传的图片
    userInfo: wx.getStorageSync("userInfo"),
    imageDetailPop: false,
    selectImg: "",
    showInformationMaintenance: false,
    showDeleteTag: false,
    delectTagId: "",
    delectTagName: "",
    packetId: '',
    projectMaterialInfo:[],
    showAddEquipment:false,
    deviceId:"扫描或手动输入设备",
    showSupplier :false,
    device:[],
    showEquipmentClass: false,
    EquipmentClass:[],
    showBatch:false,
    equipmentBatch:[],
    showAccountInforMation: false,
    networkInformation: false,
    ThirdParty:"",
    userName:'',
    passWords:'',
    ipAddress: '',
    subNetMask: '',
    defaultGateway: '',
    dnsAdress: '',
    showAddMaterials: false,
    getInputipMaterialName: "",
    getInputipMaterialNumber: "",
    getInputipMaterialUnit:"",
    powerRemark:"",
    networkRemark :"",
    showElectricityChange:false,
    electricityChange : [],
    canUseAn:false,
    installationDeviceQuery:{},
  },
  // 获取工程用料信息
  projectMaterialInformation(){
    let params = {
      zhanId: this.data.zhanIdInfo.id
    }
    let projectMaterialInfo = this.data.projectMaterialInfo
    lgRequest("projectMaterialInformation",params,{
      doSuccess:(r)=>{
        projectMaterialInfo= r.data;
        this.setData({
          projectMaterialInfo
        })
      }
    })
  },
  // 信息维护按钮弹窗
  informationMaintenance() {
    this.setData({
      showInformationMaintenance: true,
    });
  },

  // 展示增加标签弹窗
  showAddLabels() {
    this.setData({
      showAddLabels: !this.data.showAddLabels,
    });
  },
  //关闭标签弹窗
  onClose() {
    this.setData({
      showAddLabels: false,
      showInformationMaintenance: false,
      showDeleteTag: false,
      showAddEquipment : false,
      installationDeviceQuery : {},
      deviceId:"扫描或手动输入设备",

      showAddMaterials: false,
      getInputipMaterialName: "",
      getInputipMaterialNumber: "",
      getInputipMaterialUnit:"",
      powerRemark:" ",
      networkRemark :" ",
      showElectricityChange:false,
      showNetworkChange:false,
      showInformationN:false,
      showEquipmentDetail : false,
      showDeleteContent:false
    });

  },
  //增加标签方法
  addTags() {},
  // 返回
  back(){
    wx.navigateBack({
      delta: 1
    })
  },
  //导航
  toLoaction() {
    // let itemGps = this.data.zhanIdInfo.gps.split(",");
    let itemGps = this.data.zhanIdInfo.gps;
    console.log(itemGps,'这是经纬度@@@@@@@@@@@@@@@@@');
    let that = this;
    wx.openLocation({
      // latitude: Number(itemGps[1]),
      // longitude: Number(itemGps[0]),
      latitude: Number(this.data.zhanIdInfo.latitude),
      longitude: Number(this.data.zhanIdInfo.longitude),
      scale: 18,
      name: that.data.zhanIdInfo.address, // 位置名
      address: "当前位置定位", // 地址的详细说明
      success: function (res) {
        console.log("dfv");
        // success
      },
      fail: function (err) {
        console.log("dfv", err);
        // fail
      },
      complete: function () {
        // complete
      },
    });
  },
  //获取站点详情
  pointFileInfo() {
    let params = {
      siteId: this.data.zhanIdInfo.id,
    };
    lgRequest("serverList", params, {
      errAlert: false,
      doSuccess: (r) => {

        if (r.code == 200) {
          this.setData({
            equipmentList: r.data,
          });
        } else {
          wx.showToast({
            title: r.msg,
            icon: "none",
          });
        }
      },
      doComplete: (r) => {},
    });
  },
  //站点联系人
  ssiteContactList() {
    let params = {
      zhanId: this.data.zhanIdInfo.id,
    };
    lgRequest("ssiteContactList", params, {
      errAlert: false,
      doSuccess: (r) => {
        if (r.code == 200) {
          let siteContactList = r.data;
          this.setData({
            siteContactList
          });
        } else {
          wx.showToast({
            title: r.msg,
            icon: "none",
          });
        }
      },
      doComplete: (r) => {},
    });
  },
  //运维记录
  maintenanceRecords() {
    let params = {
      zhanId: this.data.zhanIdInfo.id,
    };
    lgRequest("maintenanceRecords", params, {
      errAlert: false,
      doSuccess: (r) => {
        if (r.code == 200) {
          let maintenanceRecordsInfo = r.data;
          maintenanceRecordsInfo.forEach((item) => {
            item.oTime = item.oTime ? item.oTime.split(/\s+/) : [];
          });
          this.setData({
            maintenanceRecordsInfo
          });
        } else {
          wx.showToast({
            title: r.msg,
            icon: "none",
          });
        }
      },
      doComplete: (r) => {},
    });
  },
  //站点图片
  picStateList() {
    let params = {
      siteId: this.data.zhanIdInfo.id,
      state: this.data.selectIndexType + 1,
    };
    lgRequest("picStateList", params, {
      errAlert: false,
      doSuccess: (r) => {
        if (r.code == 200) {
          console.log("站点图片", r)
          this.setData({
            picStateInfoList: r.data
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: "none",
          });
        }
      },
      doComplete: (r) => {},
    });
  },
  //删除图片
  delectImgBtn(e) {

    console.log("删除图片", e, getApp())
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    let picStateInfoList = this.data.picStateInfoList;
    let link = getApp().globalData.server;
    let Authorization = getApp().globalData.Authorization;

    if (item.id) {
      //删除图片
      let id = item.id;
      wx.request({
        url: `${link}server/picState/${id}`,
        data: {
          id
        },
        header: {
          Authorization
        },
        success: (r) => {
          picStateInfoList.splice(index, 1);
          this.setData({
            picStateInfoList
          });
          console.log("删除成功", r)

        }
      })

    }
  },
  //点击图片预览
  previewImg(e) {
    let item = e.currentTarget.dataset.item;
    this.setData({
      selectImg: item.pic,
      imageDetailPop: true,
    });
  },
  //上传图片
  afterRead(event) {
    let that = this;
    console.log(event)
    const {
      file
    } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    let url = getApp().globalData.obLineSever + "server/picState";
    file.forEach((itemFile) => {
      
        wx.uploadFile({
          // url: "http://114.115.190.196:8082/common/upload",
          // url:"https://www.mingchuliangzao.com.cn:8632/common/upload",
          url:"https://www.mengbaoonline.com:8182/common/upload",
          filePath: itemFile.path,
          name: "file",
          formData: {
            user: "test"
          },
          header: {
            "Content-Type": "multipart/form-data",
            Authorization: getApp().globalData.Authorization,
          },
          success: (res) => {
            // 上传完成需要更新 fileList 
            let data = JSON.parse(res.data);
            console.log(res)
            wx.showToast({
              title: "上传成功！",
            });
            let params = {
              siteId: that.data.zhanIdInfo.id,
              state: that.data.selectIndexType + 1,
              pic: data.url,
            }
            lgRequest("addPicState", params, {
              doSuccess: (res) => {
                // console.log(res)
                if (res.code == 200) {
                  console.log(res,);
                  this.picStateList()
                }
              }
      
            })
           

          },
          fail(error) {
            wx.showToast({
              title: "上传失败",
            });
            console.log(error,'这是上传图片的错误')
          },
        });
      
      console.log(itemFile)
     
      // wx.uploadFile({
      //   url: "https://www.mingchuliangzao.com.cn:8632/common/upload",
      //   filePath: itemFile.path,
      //   name: "file",
      //   formData: {
      //     user: "test"
      //   },
      //   success(res) {
      //     // 上传完成需要更新 fileList
      //     let data = JSON.parse(res.data);
      //     let obj = {
      //       pic: data.url,
      //     };
      //     let picStateInfoList = that.data.picStateInfoList;
      //     picStateInfoList.unshift(obj);
      //     that.setData({
      //       picStateInfoList,
      //     });
      //   },
      //   fail(error) {
      //     wx.showToast({
      //       title: "上传失败，请稍后再试！",
      //     });
      //   },
      // });
    });
  },
  closePop() {
    this.setData({
      imageDetailPop: false,
    });
  },
  selectItem(e) {
    this.setData({
      selectIndex: e.currentTarget.dataset.type,
    });

  },
  // 上传站点状态
  changeStatus() {
    let params = {
      zid: this.data.zhanIdInfo.id,
      state: this.data.selectIndexType + 1,
    }
    lgRequest('changeStatus', params, {
      doSuccess: (r) => {
        console.log("修改状态", r)
        this.querySiteInfo();
        wx.showToast({
          title: '修改成功',
        })
      }
    })
  },

  // 点击修改状态
  clickSelectIndexType(e) {
    this.setData({
      selectIndexType: e.currentTarget.dataset.type,
    });
    this.picStateList();
    console.log(e)
  },
  // 获取站点图片
  picStateList() {
    let params = {
      siteId: this.data.zhanIdInfo.id,
      state: this.data.selectIndexType + 1,
    };
    let picStateInfoList = this.data.picStateInfoList;
    lgRequest("picStateList", params, {
      doSuccess: (r) => {
        console.log("站点图片", r)

          picStateInfoList = r.data

        this.setData({
          picStateInfoList
        })

      }
    })
  },
  // 查询站点状态施工进度
  constructionProgress() {
    let params = {
      siteId: this.data.zhanIdInfo.id
    }
    console.log("123456", params)
    lgRequest("constructionProgress", params, {
      doSuccess: (r) => {
        console.log("施工状态", r)
        this.setData({
          switchList: r.data
        })
      }
    })
  },
  // 修改站点状态-施工-进度
  selectItemSwitch(e) {
    let index = e.currentTarget.dataset.index;
    let switchList = this.data.switchList;
    switchList[index].value = switchList[index].value == 1 ? "0" : "1";
    let selectSwitchItem = e.currentTarget.dataset.item;
    this.setData({
      switchList,
      selectSwitchItem,
    });
    console.log("状态按钮传参", e.currentTarget.dataset)
    let params = {
      id: this.data.switchList[index].id,
      value: this.data.switchList[index].value,
    };
    lgRequest("modificationOfConstructionSchedule", params, {
      doSuccess: (r) => {
        console.log("修改成功", r)
      }
    })
  },
  selectItemSwitchOne(e) {
    let index = e.currentTarget.dataset.index;
    let switchListOne = this.data.switchListOne;
    switchListOne[index].value = switchListOne[index].value == 1 ? "0" : "1";
    let selectSwitchItem = e.currentTarget.dataset.item;
    this.setData({
      switchListOne,
      selectSwitchItem,
    });
    console.log("状态按钮传参", e.currentTarget.dataset)
    let params = {
      id: this.data.switchListOne[index].id,
      value: this.data.switchListOne[index].value,
    };
    lgRequest("zhandiantingyon", params, {
      doSuccess: (r) => {
        console.log("修改成功", r)
      }
    })
  },
  // 记录类型
  reportTap() {
    this.setData({
      reportPop: !this.data.reportPop,
    });
  },
  selectKeyItem(e) {
    this.setData({
      selectKey: e.currentTarget.dataset.item,
      reportPop: !this.data.reportPop,
    });
  },
  //根据详情修改站点状态
  // changeStateType() {
  //   let switchList = this.data.switchList;
  //   switchList.forEach((item) => {
  //     if (this.data.zhanIdInfo.speed.indexOf(item.nameDetail != -1)) {
  //       item.isSelect = true;
  //     }
  //   });
  //   this.setData({
  //     switchList
  //   });
  // },
  //站点信息修改
  editStateDetail() {
    let item = encodeURIComponent(JSON.stringify(this.data.zhanIdInfo));
    wx.navigateTo({
      url: `../stateInformateMainte/stateInformateMainte?item=${item}`,
    });
  },
  //获取站点信息
  getstationService() {
    lgRequest(
      "stationService", {}, {
        errAlert: false,
        doSuccess: (r) => {
          if (r.code == 200) {

            this.setData({
              stationServiceInfo: r.data,
            });
            this.getTagName();
            this.constructionProgress() //获取施工状态

            // resolve(r.data)
          } else {
            // wx.showToast({
            //   title: r.msg,
            //   icon: 'none'
            // })
          }
        },
        doComplete: (r) => {},
      }
    );
  },
  //发送增加标签请求
  addTagsRequest(e) {
    console.log(e)
    let tagId = e.currentTarget.dataset.value
    let index = this.data.tagName.findIndex(row => row.siteTag == tagId)
    if (index != -1) {
      wx.showToast({
        title: '您已添加该标签！',
        icon: 'none'
      })
      this.setData({
        showAddLabels: false
      })
      return
    }
    let params = {
      siteId: this.data.zhanIdInfo.id,
      tag: e.currentTarget.dataset.valueid,
      valueId: e.currentTarget.dataset.value,

    };

    lgRequest("addSiteTag", params, {
      errAlert: false,
      doSuccess: (r) => {
        if (r.code == 200) {
          this.getTagName()
        } else {}
      },
      doComplete: (r) => {},
    });
    this.onClose();
  },
  //获取标签名字
  getTagName(e) {
    let params = {
      siteId: this.data.zhanIdInfo.id
    }
    lgRequest("deleteTags", params, {
      errAlert: true,
      doSuccess: (r) => {
        if (r.code == 200) {


          this.setData({
            tagName: r.data
          })

        }
      },
      doFail: (err) => {
        console.log(err)
      }
    })


  },
  //展示删除站点标签窗口
  showDeleteTag(e) {

    this.setData({
      showDeleteTag: true,
      delectTagId: e.currentTarget.dataset.valueid,
      delectTagName: e.currentTarget.dataset.valuename,
    })
  },
  // 删除站点标签
  delectTags() {
    let link = getApp().globalData.server;

    wx.request({
      url: `${link}server/SiteTag/${this.data.delectTagId}`,
      data: {
        id: this.data.delectTagId,
      },
      header: {
        'Authorization': wx.getStorageSync('token')
      },
      method: "DELETE",
      success(res) {
        console.log(res)
      }
    })

    let index = this.data.tagName.findIndex(
      (row) => row.siteTag == this.data.delectTagName
    )
    if (index != -1) {
      let tagName = this.data.tagName;
      tagName.splice(index, 1);
      this.setData({
        tagName,
      })
      this.onClose();
      wx.showToast({
        title: '删除成功！',
        icon: 'none'
      })

    }
  },
  // 查询站点信息
  querySiteInfo() {
    let params = {
      zId: this.data.zhanIdInfo.id
    }
    // let Authorization= getApp().globalData.Authorization;
    let Authorization = wx.getStorageSync('token');
    let a = getApp().globalData.server;
    let zhanIdInfo = {

    }
    wx.request({
      url: `${a}server/site/${params.zId}`,
      data:params,
      method: "GET",
      header:{
        Authorization:Authorization
      },
      success: (r)=>{
        console.log(r)
        zhanIdInfo = r.data.data;
        this.setData({
          zhanIdInfo
        })
        // 页面间传参监听事件
        // const eventChannel = this.getOpenerEventChannel()
        // getApp().pageBeventChannel = eventChannel
        // eventChannel.emit('PageAacceptDataFromPageB', { data: zhanIdInfo});
      }
    })
    // lgRequest({
    //   url: `server/site/list/${params.zId}`,
    //   method: 'get'
    // }, params, {
    //   doSuccess: (r) => {
    //     console.log("站点信息", r)
    //   }
    // })
  },
  // 安装设备弹窗
  add(){
    this.setData({
      showAddEquipment : true
    })
  },
  // 扫码
  saoma(){
    let deviceId = this.data.deviceId
    console.log(111111)
    wx.scanCode({
      success: (r)=>{
        deviceId = r.result;
        this.setData({
          deviceId
        })
      }
    })
  },
  // 获取设备信息
  installationDeviceQuery(){
    this.setData({
      canUseAn:true
    })
    let installationDeviceQuery = this.data.installationDeviceQuery;
    let link = getApp().globalData.server;
    let Authorization = getApp().globalData.Authorization;
    let deviceId = this.data.deviceId
    wx.request({
      url: `${link}server/info/${deviceId}`,
      header:{
        Authorization
      },
      success:(r)=>{
        if(r.data.data){
          installationDeviceQuery = r.data.data
          console.log(r)
        }
       
        if (!r.data.data){
          wx.showToast({
            title: '查无此设备!',
            icon: 'none'
          })
          this.setData({
            notDId : true
          })
        }
        this.setData({
          installationDeviceQuery
        })
      }
    })
  },
  // 获取输入款数据
  getInput(e){
      console.log("input",e)
      let deviceId = this.data.deviceId;
      deviceId=e.detail.value
      this.setData({
        deviceId
      })
    
    
  },
  // 展示供应商弹窗
  showDeviceType(){
    if(!this.data.canUseAn){
      return
    }
    console.log(11111)
    this.setData({
      showSupplier : true
    })
    lgRequest("supplierList",{},{
      doSuccess:(r)=>{
        console.log(r)
        this.setData({
          device : r.data
        })
      }
    })

  },
  // 选择供应商
  selectSuppliers(e){
    console.log(e.currentTarget.dataset.item.supplierName)
    let installationDeviceQuery = this.data.installationDeviceQuery;
    installationDeviceQuery.supplierName = e.currentTarget.dataset.item.supplierName;
    installationDeviceQuery.supplierId = e.currentTarget.dataset.item.id;
  
    let a = this.data;
    // a.id = 11
    console.log(a)
    this.setData({
      installationDeviceQuery,
      showSupplier : false
      
    })
  },
  // 展示设备类型弹窗
  showEquipmentClass(){
    if(!this.data.canUseAn){
      return
    }
    this.setData({
      showEquipmentClass : true
    })
    lgRequest('pointFileInfo',{},{
      doSuccess:(r)=>{
        console.log(r)
        this.setData({
          EquipmentClass : r.data
        })
      }
    })
  },
  // 选择设备类型
  selectEquipmentClass(e){
    let installationDeviceQuery = this.data.installationDeviceQuery;
    installationDeviceQuery.deviceName = e.currentTarget.dataset.item.deviceName;
    installationDeviceQuery.deviceId = e.currentTarget.dataset.item.deviceId;
    // installationDeviceQuery= 1
    this.setData({
      installationDeviceQuery,
      showEquipmentClass : false
      
    })
  },
// 展示批次弹窗
  showBatch(){
    if(!this.data.canUseAn){
      return
    }
    this.setData({
      showBatch : true
    })
    let params = {
      
      supplierId:this.data.installationDeviceQuery.supplierId,
      deviceId:this.data.installationDeviceQuery.deviceId,

    }
    lgRequest('tabDeviceList',params,{
      doSuccess:(r)=>{
        console.log(r)
        this.setData({
          equipmentBatch : r.data
        })
      }
    })
  },
  // 选择批次
  selectEquipmentBatch(e){
    console.log(e)
    let installationDeviceQuery = this.data.installationDeviceQuery;
    installationDeviceQuery.purchaseTime = e.currentTarget.dataset.item.purchaseTime;
    installationDeviceQuery.batchId=e.currentTarget.dataset.item.batchId;

    this.setData({
      installationDeviceQuery,
      showBatch : false
      
    })
  },
  // 展示网络信息框
  showAccountInforMation(){
    let showAccountInforMation = !this.data.showAccountInforMation
    this.setData({
      showAccountInforMation
    })
  },

  networkInformation(){
    let networkInformation = !this.data.networkInformation
    this.setData({
      networkInformation
    })
  },
  // 获取第三方标识
  getInputThirdParty(e){
    console.log("input",e)
    let ThirdParty = this.data.ThirdParty;
    ThirdParty=e.detail.value
    this.setData({
      ThirdParty
    })
  },
  getInputuserName(e){
    console.log("input",e)
    let getInputuserName = this.data.getInputuserName;
    getInputuserName=e.detail.value
    this.setData({
      getInputuserName
    })
  },
  getInputpassWords(e){
    console.log("input",e)
    let getInputpassWords = this.data.getInputpassWords;
    getInputpassWords=e.detail.value
    this.setData({
      getInputpassWords
    })
  },
  getInputipAddress(e){
    console.log("input",e)
    let getInputipAddress = this.data.getInputipAddress;
    getInputipAddress=e.detail.value
    this.setData({
      getInputipAddress
    })
  },
  getInputsubNetMask(e){
    console.log("input",e)
    let getInputsubNetMask = this.data.getInputsubNetMask;
    getInputsubNetMask=e.detail.value
    this.setData({
      getInputsubNetMask
    })
  },
  getInputdefaultGateway(e){
    console.log("input",e)
    let getInputdefaultGateway = this.data.getInputdefaultGateway;
    getInputdefaultGateway=e.detail.value
    this.setData({
      getInputdefaultGateway
    })
  },
  getInputdnsAdress(e){
    console.log("input",e)
    let getInputdnsAdress = this.data.getInputdnsAdress;
    getInputdnsAdress=e.detail.value
    this.setData({
      getInputdnsAdress
    })
  },
  // 提交安装设备
  submitDeviceInstall(){
    let installationDeviceQuery = this.data.installationDeviceQuery
    if(this.data.notDId){
      
      let params = [{
        deviceId:installationDeviceQuery.deviceId,
        batchId:installationDeviceQuery.batchId,
        // deviceModel:installationDeviceQuery.deviceModel,
        deviceState:1,
        siteId:this.data.zhanIdInfo.id,
        supplierId:installationDeviceQuery.supplierId,
        deviceCode : this.data.deviceId,
        // account: this.data.ThirdParty,
        dns: this.data.getInputdnsAdress,
        ip: this.data.getInputipAddress,
        possword: this.data.getInputpassWords,
        wangguan: this.data.getInputdefaultGateway,
        subnet: this.data.getInputsubNetMask,
        account: this.data.getInputuserName,
        identification: this.data.getInputuserName

      }]
      lgRequest('submitDeviceInstallNot',params,{
        doSuccess:r=>{
          console.log(r)
          this.pointFileInfo()
          this.setData({
            showAddEquipment: false
          })
        }
      })
     
      return
    }
    let params = {
      siteId : this.data.zhanIdInfo.id,
      id: this.data.deviceId

    };
    lgRequest("submitDeviceInstall",params,{
      doSuccess: (r)=>{
        console.log(r)
        if(r.code ==200){
          wx.showToast({
            title: '安装成功!',
            icon: 'none'
          })
       

        }else{
          wx.showToast({
            title: '请输入设备id!',
            icon: 'none'
          })
        }
      },
      doFail:(err)=>{
        console.log(err)
        wx.showToast({
          title: '请输入设备id!',
          icon: 'none'
        })
      }
    })
  },
  // 添加工程用料
  addMaterials(){
    this.setData({
      showAddMaterials : true
    })
  },
  // 获取输入款用料名
  getInputipMaterialName(e){
    let getInputipMaterialName= e.detail.value;
    this.setData({
      getInputipMaterialName
    })
  },
  // 获取输入款用料数量
  getInputipMaterialNumber(e){
    let getInputipMaterialNumber= e.detail.value;
    this.setData({
      getInputipMaterialNumber
    })
  },
  // 获取输入款用料批次
  getInputipMaterialUnit(e){
    let getInputipMaterialUnit= e.detail.value;
    this.setData({
      getInputipMaterialUnit
    })
  },
  // 获取输入款电力信息
  getInputpowerRemark(e){
    console.log("eeeee",e)
    let powerRemark = e.detail.value;
    this.setData({
      powerRemark
    })
  },
  // 获取输入款网络信息
  getInputnetworkRemark(e){

    let networkRemark = e.detail.value;
    this.setData({
      networkRemark
    })
  },
  // 提交设备输入款
  submitEquipmentInput(){
    let params={
      name : this.data.getInputipMaterialName,
      number : this.data.getInputipMaterialNumber,
      unit : this.data.getInputipMaterialUnit,
      siteId : this.data.zhanIdInfo.id,
    }
    lgRequest("submitEquipmentInput",params,{
      doSuccess:(r)=>{
        wx.showToast({
          title: '安装成功!',
          icon: 'none'
        })
        this.onClose();
        this.projectMaterialInformation();//获取工程用料

      }
    })
    
  },
  // 提交电力信息
  submitPowerRemark(){
    // let params = {
    //   zId:this.data.zId,
    //   powerRemark:this.data.powerRemark,
    //   zId:this.data.zId,
    // }
    let params = {
      zid:this.data.zhanIdInfo.id,
      powerRemark:this.data.powerRemark,
      
    };
    let zhanIdInfo= this.data.zhanIdInfo;
    zhanIdInfo.powerRemark=params.powerRemark
    lgRequest("submitPowerRemark",params,{
      doSuccess:(r)=>{
        console.log(r)
        this.onClose();
        this.ElectricityChange()
        this.setData({
          zhanIdInfo
        })
  
      }
    })

  },
  showElectricityChange(){
    this.setData({
      showElectricityChange:true,
    });
    
  },
  // 获取电力变更记录
  ElectricityChange(){
    let params = {
      zhanId : this.data.zhanIdInfo.id,
      type : 4,
    };
    let electricityChange = []
    lgRequest("showElectricityChange",params,{
      doSuccess:(r)=>{
        electricityChange = r.data;
        this.setData({
          electricityChange
        })
        this.eInfo()
      }
    })
  },
  // 关闭添加设备中得弹框
  onCloseEquipment(){
    this.setData({
      showSupplier : false,
      showEquipmentClass : false,
      showBatch: false,
    })
    
  },

  //上传信息维护记录
  subInformationMaintenanceBt(){
    let params = {
      zhanId : this.data.zhanIdInfo.id,
      type : 4,
      nextContent : this.data.powerRemark
    }
    lgRequest('subInformationMaintenanceBt',params,{
      doSuccess:(r)=>{
        console.log(r)
        this.InformationMaintenanceBtTx();
        let zhanIdInfo = this.data.zhanIdInfo;
        zhanIdInfo.networkRemark = nextContent;
        this.setData({
          zhanIdInfo
        })
      }
    })
  },
//   拨打电话
call(){
    wx.makePhoneCall({
        
        phoneNumber: '19156972414',
        
        success: function () {
          console.log("拨打电话成功！")
        },
        fail: function () {
          console.log("拨打电话失败！")
        }
      })
    // console.log(111);
      console.log(this.zhanIdInfo);
      
},
  // 获取站点电力信息备注
  eInfo(){
    // let eInfo = this.data.electricityChange[0].content?this.data.electricityChange[0].content:''
    // this.setData({
    //   eInfo
    // })
  },
  // 获取网络信息备注
  nInfo(){
    // let nInfo = this.data.electricityChange[0].content?this.data.electricityChange[0].content:''
    // this.setData({
    //   nInfo
    // })
  },
  // 展示网络变更记录
  showNetworkChange(){
    this.setData({
      showNetworkChange:true,
    });
  },
  // 网络变更记录
  NetworkChange(){
    let params = {
      zhanId : this.data.zhanIdInfo.id,
      type : 5,
    };
    let NetworkChange = []
    lgRequest("showElectricityChange",params,{
      doSuccess:(r)=>{
        NetworkChange = r.data;
        this.setData({
          NetworkChange
        })
        this.nInfo()
      }
    })
  },
  // 提交网络变更信息
  subInformationMaintenanceBtn(){
    let params = {
      zid:this.data.zhanIdInfo.id,
      networkRemark:this.data.networkRemark,
    }
    let zhanIdInfo = this.data.zhanIdInfo;
    zhanIdInfo.networkRemark = params.networkRemark
    lgRequest('submitPowerRemark',params,{
      doSuccess:(r)=>{
        console.log(r)
        this.onClose();
        this.NetworkChange()
        this.setData({
          zhanIdInfo
        })
        
      }
    })
  },
  // 弹出信息维护界面
  informationN() {
    this.setData({
      showInformationN: true,
    });
  },
  // 展示设备详情
  itemDetail(e){
    console.log(e)
  //  dpd
    let EquipmentDetail = e.currentTarget.dataset.item;
    console.log(EquipmentDetail)
    this.setData({
      showEquipmentDetail : true,
      EquipmentDetail
    })

  },
  // 展示删除工程用料
  showDeleteContent(e){
    
    console.log(e)
    this.setData({
      showDeleteContent:true,
      DeleteContent:e.currentTarget.dataset.item.id
    })
  },
  // 删除工程用料
  DeleteContent(){
    let params = {
      id:this.data.DeleteContent
    }
    lgRequest('DeleteContent',params,{
      doSuccess:r=>{
        console.log(r)
        this.onClose()
        this.projectMaterialInformation();//获取工程用料
      }
    })
  },
  // 显示修改设备详情
  showChangeEquipmentDetail(){
    this.setData({
      showChangeEquipmentDetail:true
    })
  },
  hodeChangeEquipmentDetail(){
    this.setData({
      showChangeEquipmentDetail:false
    })
  },
  get3(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.remark = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getu(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.subnet = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getP(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.password = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getI(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.ip = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getZ(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.account = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getM(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.wangguan = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  getD(e){
    let EquipmentDetail = this.data.EquipmentDetail
    EquipmentDetail.dns = e.detail.value;
    this.setData({
      EquipmentDetail
    })
  },
  submitChangeED(){
    let params =this.data.EquipmentDetail
    lgRequest('submitDeviceInstall',params,{
      doSuccess:r=>{
        this.hodeChangeEquipmentDetail()
      }
    })
    
  },
  showDeleteEDED(){
    this.setData({
      showDeleteEDED:true
    })
  },
  onClose2(){
  this.setData({
  showDeleteEDED:false
})
  },
  delectED(){
      let dIds=this.data.EquipmentDetail.id
    
    lgRequest('shanchuED',{dIds},{
      doSuccess:r=>{
        console.log(r)
        this.onClose2()
        this.onClose()
        this.hodeChangeEquipmentDetail()
        this.pointFileInfo()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    if (options.type == 2) {
      this.setData({
        selectIndex: 2,
      });
    } else if (options.type == 3) {
      this.setData({
        selectIndex: 3,
      });
    }
    this.setData({
      zhanIdInfo: JSON.parse(decodeURIComponent(options.zhanIdInfo)),
      selectIndexType: Number(JSON.parse(decodeURIComponent(options.zhanIdInfo)).state) - 1,
      // packetId: JSON.parse(decodeURIComponent(options.packetId)),
    });
    this.pointFileInfo();
    this.ssiteContactList();
    this.maintenanceRecords(); //运维记录
    this.picStateList(); //获取站点图片
    this.projectMaterialInformation();//获取工程用料
    this.ElectricityChange();//获取变更记录
    if (this.data.zhanIdInfo.state == 2 && this.data.zhanIdInfo.speed) {
      // this.changeStateType();
    }
    this.getstationService(); //获取标签
    console.log('svb')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    console.log(this.data,'这是data')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});